package com.jy.appmarket.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jy.app.market.apk.type.CommentType;
import com.jy.app.market.idata.data.Comment;
import com.jy.appmarket.R;
import com.jy.appmarket.utils.LoadImageUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

public class CommentAdapter extends SimpleBaseAdapter<Comment> {

	public CommentAdapter(Context context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Comment comment = mList.get(position);
		ViewHolder holder;
		if (convertView == null) {
			convertView = getInflater().inflate(R.layout.appcomment_item, parent, false);
			holder = new ViewHolder();
			holder.icon = convertView.findViewById(R.id.user_icon);
			holder.name = convertView.findViewById(R.id.author_name);
			holder.date = convertView.findViewById(R.id.date);
			holder.content = convertView.findViewById(R.id.content);
			holder.heart = convertView.findViewById(R.id.heart);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		ImageLoader.getInstance().displayImage(comment.getIconUrl(), holder.icon,
				LoadImageUtils.getListIconDisplayOption(mContext));
		holder.name.setText(comment.getNickName());
		holder.date.setText(comment.getTime());
		holder.content.setSingleLine(false);
		holder.content.setText(comment.getContent());
		holder.heart.setVisibility(View.VISIBLE);
		if (CommentType.BAD == comment.getEvaluate()) {
			holder.heart.setImageResource(R.drawable.icon_dislike_f);
		} else if (CommentType.GOOD == comment.getEvaluate()) {
			holder.heart.setImageResource(R.drawable.icon_like_f);
		}else{
			holder.heart.setImageResource(R.drawable.transparent);
		}

		return convertView;
	}

	private static class ViewHolder {
		ImageView icon;
		TextView name;
		TextView date;
		TextView content;
		ImageView heart;
	}

}
